package lego.diagram.edit.policies;

import lego.diagram.edit.commands.LightSensorCreateCommand;
import lego.diagram.edit.commands.MicroSensorCreateCommand;
import lego.diagram.edit.commands.MotorActionerCreateCommand;
import lego.diagram.edit.commands.PicoNetCreateCommand;
import lego.diagram.edit.commands.RobotCreateCommand;
import lego.diagram.edit.commands.TouchSensorCreateCommand;
import lego.diagram.edit.commands.UltraSoundSensorCreateCommand;
import lego.diagram.providers.LegoElementTypes;

import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.emf.commands.core.commands.DuplicateEObjectsCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DuplicateElementsRequest;

/**
 * @generated
 */
public class RootItemSemanticEditPolicy extends LegoBaseItemSemanticEditPolicy {

	/**
	 * @generated
	 */
	public RootItemSemanticEditPolicy() {
		super(LegoElementTypes.Root_1000);
	}

	/**
	 * @generated
	 */
	protected Command getCreateCommand(CreateElementRequest req) {
		if (LegoElementTypes.MicroSensor_2001 == req.getElementType()) {
			return getGEFWrapper(new MicroSensorCreateCommand(req));
		}
		if (LegoElementTypes.PicoNet_2002 == req.getElementType()) {
			return getGEFWrapper(new PicoNetCreateCommand(req));
		}
		if (LegoElementTypes.UltraSoundSensor_2003 == req.getElementType()) {
			return getGEFWrapper(new UltraSoundSensorCreateCommand(req));
		}
		if (LegoElementTypes.TouchSensor_2004 == req.getElementType()) {
			return getGEFWrapper(new TouchSensorCreateCommand(req));
		}
		if (LegoElementTypes.LightSensor_2005 == req.getElementType()) {
			return getGEFWrapper(new LightSensorCreateCommand(req));
		}
		if (LegoElementTypes.Robot_2006 == req.getElementType()) {
			return getGEFWrapper(new RobotCreateCommand(req));
		}
		if (LegoElementTypes.MotorActioner_2007 == req.getElementType()) {
			return getGEFWrapper(new MotorActionerCreateCommand(req));
		}
		return super.getCreateCommand(req);
	}

	/**
	 * @generated
	 */
	protected Command getDuplicateCommand(DuplicateElementsRequest req) {
		TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
				.getEditingDomain();
		return getGEFWrapper(new DuplicateAnythingCommand(editingDomain, req));
	}

	/**
	 * @generated
	 */
	private static class DuplicateAnythingCommand extends
			DuplicateEObjectsCommand {

		/**
		 * @generated
		 */
		public DuplicateAnythingCommand(
				TransactionalEditingDomain editingDomain,
				DuplicateElementsRequest req) {
			super(editingDomain, req.getLabel(), req
					.getElementsToBeDuplicated(), req
					.getAllDuplicatedElementsMap());
		}

	}

}
